unit frmDMGeral;

interface                     
uses
  SysUtils, Classes, MDODatabase, DB, Registry, Dialogs, Controls, Forms;

type
  TDMGeral = class(TDataModule)
    Conexao: TMDODatabase;
    TrConexao: TMDOTransaction;
    procedure DataModuleCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  DMGeral: TDMGeral;

implementation

uses frmConfPath;

{$R *.dfm}

procedure TDMGeral.DataModuleCreate(Sender: TObject);
var
  oReg: TRegistry;
  lOk: Boolean;
begin
  oReg := TRegistry.Create;
  Conexao.Close;
  try
    if oReg.OpenKey('Software\MultForms Software\ALFood', False) then begin
      try
        Conexao.DatabaseName := oReg.ReadString('DB');
        with Conexao.Params do begin
          Clear;
          Add('user_name=' + oReg.ReadString('US'));
          Add('password=' + oReg.ReadString('PS'));
        end;
        Conexao.Open;
        lOk := True;
      except
        on e:exception do begin
          lOk := False;
          ShowMessage('Erro: '+ #13 + e.Message);
        end;
      end;
      oReg.CloseKey;
    end
    else begin
      lOk := False;
    end;
  finally
    oReg.Free;
  end;
  if not lOk then begin
    if not Assigned(F_ConfPath) then
      F_ConfPath := TF_ConfPath.Create(Self);
    F_ConfPath.ShowModal;
    if F_ConfPath.ModalResult <> mrOk then begin
      Application.Terminate;
    end;
  end;
end;

end.
